package com.niit.session18;

import java.util.TreeMap;

import com.niit.session17.Student;

public class TreeMapDemo {
	public static void main(String[] args) {
//		TreeMap可以把存进去的元素根据键排序
		TreeMap<Integer, Student> treeMap = new TreeMap<Integer,Student>();
		Student student1 = new Student("张三",18);
		Student student2= new Student("李四",20);
		Student student3= new Student("王五",22);
//		Map的值也可以存自己定义的对象，而且值可以重复
		treeMap.put(2, student1);
		treeMap.put(1, student1);
		treeMap.put(3, student2);
//		如果存储了重复的键，后面的数据会把前面的覆盖
		treeMap.put(4, student2);
		treeMap.put(4, student3);
		System.out.println(treeMap.get(4));
		System.out.println(treeMap);
		
	}
	
	

}
